home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / apps.to.go / DTS.Draw / DoEvent.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-10  |  5.1 KB  |  204 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        DoEvent.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1990-1993 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* You may incorporate this sample code into your applications without
  12. ** restriction, though the sample code has been provided "AS IS" and the
  13. ** responsibility for its operation is 100% yours.  However, what you are
  14. ** not permitted to do is to redistribute the source as "DSC Sample Code"
  15. ** after having made changes. If you're going to re-distribute the source,
  16. ** we require that you make it clear in the source that the code was
  17. ** descended from Apple Sample Code, but that you've made changes. */
  18.  
  19.  
  20.  
  21. /*****************************************************************************/
  22.  
  23.  
  24.  
  25. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  26. #include "App.protos.h"        /* Get the prototypes for application.            */
  27.  
  28. #ifndef __CTLHANDLER__
  29. #include "CtlHandler.h"
  30. #endif
  31.  
  32. #ifndef __DESK__
  33. #include <Desk.h>
  34. #endif
  35.  
  36. #ifndef __DISKINIT__
  37. #include <DiskInit.h>
  38. #endif
  39.  
  40. #ifndef __ERRORS__
  41. #include <Errors.h>
  42. #endif
  43.  
  44. #ifndef __MENUS__
  45. #include <Menus.h>
  46. #endif
  47.  
  48. #ifndef __TEXTEDITCONTROL__
  49. #include "TextEditControl.h"
  50. #endif
  51.  
  52. #ifndef __TOOLUTILS__
  53. #include <ToolUtils.h>
  54. #endif
  55.  
  56. #ifndef __UTILITIES__
  57. #include "Utilities.h"
  58. #endif
  59.  
  60.  
  61.  
  62. /*****************************************************************************/
  63.  
  64.  
  65.  
  66. extern Cursor    *gCursorPtr;    /* See the file Window.c for comments about this global. */
  67.  
  68.  
  69.  
  70. /*****************************************************************************/
  71. /*****************************************************************************/
  72.  
  73.  
  74.  
  75. /* Do the right thing for an event.  Determine what kind of event it is, and
  76. ** call the appropriate routines. */
  77.  
  78. #pragma segment Main
  79. void    DoEvent(EventRecord *event)
  80. {
  81.     Point        pt;
  82.     OSErr        err;
  83.  
  84.     switch(event->what) {
  85.  
  86.         case nullEvent:
  87.             DoIdleTasks(event);
  88.             break;
  89.  
  90.         case mouseDown:
  91.             DoMouseDown(event);            /* Let framework handle mouse downs. */
  92.             break;
  93.  
  94.         case autoKey:
  95.         case keyDown:
  96.             DoKeyDown(event);            /* Let framework handle key events. */
  97.             break;
  98.  
  99.         case activateEvt:
  100.             gCursorPtr = nil;            /* Force recalculation of the cursor. */
  101.             DoActivate((WindowPtr)event->message);
  102.             break;
  103.  
  104.         case updateEvt:
  105.             DoUpdate((WindowPtr)event->message);
  106.             break;
  107.  
  108.         case kHighLevelEvent:
  109.             gCursorPtr = nil;            /* Force recalculation of the cursor. */
  110.             DoHighLevelEvent(event);
  111.             break;
  112.  
  113.         case osEvt:
  114.             gCursorPtr = nil;            /* Force recalculation of the cursor. */
  115.             switch ((event->message >> 24) & 0xFF) {
  116.                     /* Must logical and with 0xFF to get only low byte. */
  117.                     /* High byte of message. */
  118.  
  119.                 case mouseMovedMessage:
  120.                     DoIdleTasks(event);        /* Treat mouseMoved events like NULL events. */
  121.                     break;
  122.  
  123.                 case suspendResumeMessage:
  124.                         /* Suspend/resume is also an activate/deactivate. */
  125.                     gInBackground = !((event->message) & resumeFlag);
  126.                     CTEConvertClipboard((event->message) & convertClipboardFlag, !gInBackground);
  127.                     DoActivate(FrontWindow());
  128.                     HiliteWindows();
  129.                     break;
  130.             }
  131.             break;
  132.  
  133.         case diskEvt:
  134.             gCursorPtr = nil;            /* Force recalculation of the cursor. */
  135.             if (HiWord(event->message) != noErr) {
  136.                 SetPt(&pt, kDILeft, kDITop);
  137.                 err = DIBadMount(pt, event->message);
  138.             }        /* It is not a bad idea to at least call DIBadMount in response to */
  139.             break;    /* a diskEvt, so that the user can format a floppy. */
  140.     }
  141.  
  142.     DoCursor();
  143.     DoAdjustMenus();
  144. }
  145.  
  146.  
  147.  
  148. /*****************************************************************************/
  149.  
  150.  
  151.  
  152. /* •• Called by DTS.Lib..framework. •• */
  153.  
  154. /* This is called when a window is activated or deactivated. */
  155.  
  156. #pragma segment Main
  157. void    DoActivate(WindowPtr window)
  158. {
  159.     RgnHandle    rgn, oldClip;
  160.     Point        pt;
  161.  
  162.     NotifyCancel();
  163.  
  164.     if (IsAppWindow(window)) {
  165.  
  166.         SetPort(window);
  167.         DoCtlActivate(window);
  168.         DoDrawFrame(window, true);            /* Redraw frame for new activate state. */
  169.  
  170.         CopyRgn(((WindowPeek)window)->contRgn, rgn = NewRgn());
  171.         DiffRgn(rgn, ((WindowPeek)window)->updateRgn, rgn);
  172.             /* Don't draw any part that's already destined to draw due to an update event.
  173.             ** This prevents part of an exposed window from drawing twice, and thus avoids
  174.             ** flickering. */
  175.  
  176.         BeginContent(window);
  177.  
  178.         pt.h = pt.v = 0;
  179.         GlobalToLocal(&pt);
  180.         OffsetRgn(rgn, pt.h, pt.v);
  181.             /* This offset may seem wrong, since the origin may not be 0,0.  It is actually correct,
  182.             ** since at the time of the GlobalToLocal, the port's origin was set to the content origin.
  183.             ** A clearer way to look at this is in two steps:
  184.             ** 1) With the port's origin at 0,0, do a GlobalToLocal on 0,0, and then offset the new clip
  185.             **    by that amount.
  186.             ** 2) Once the port's origin is set correctly, the new clip needs to be offset again, based
  187.             **    on the origin value.  (The clipRgn travels with the origin, unlike the visRgn.)
  188.             ** The above is what automatically happens when you do the GlobalToLocal of 0,0 on the
  189.             ** correct origin.  Offsets are additive.  One step -- no muss, no fuss. */
  190.  
  191.         GetClip(oldClip = NewRgn());
  192.         SetClip(rgn);
  193.         DoDrawControls(window, true);        /* Redraw content scrollbars for new activate state. */
  194.         SetClip(oldClip);
  195.         DisposeRgn(oldClip);
  196.         DisposeRgn(rgn);
  197.  
  198.         EndContent(window);
  199.     }
  200. }
  201.  
  202.  
  203.  
  204.